<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>修改密码</title>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body class="retrieve-body">
<input type="hidden" id="userName" th:value="${session.userAccount}"/>
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<script>
    var uname = $('#userName').val();
    if(uname == ''){
        window.location.href = "toRetrieve.do";
    }
    var ustatusid = $('#UserStatusid').val();
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
</script>
<form action="" method="post">
    <div class="retrieve">
        <div class="retrieve-text">
            <ul>
                <li><label for="userPassword">新密码:</label></li>
                <!--<li>提问:</li>-->
                <li><label for="userRepassword">请确认:</label></li>
                <!--<li>密码:</li>-->
            </ul>
        </div>
        <div class="retrieve-input">
            <ul>
                <li>
                    <input type="password" id="userPassword"/>
                </li>
                <!--<li>-->
                    <!--<span th:text="{userQuestion}"></span>-->
                <!--</li>-->
                <li>
                    <input type="password" id="userRepassword"/>
                </li>
                <!--<li><span></span></li>-->
            </ul>
        </div>
    </div>
    <div class="btnretrieve">
        <button class="btn-retrieve" id="btn-update" type="button">修改</button>
        <button class="retrieve-cancel" type="reset">取消</button>
    </div>
</form>
</body>
<script type="text/javascript">
    $('#userPassword').blur(checkUserPassword);
    $('#userRepassword').blur(checkUserRepassword);
    var userPassword;
    function checkUserPassword() {
        userPassword = $('#userPassword').val();
        var reg_userPassword = /^\w{6,10}$/;
        var flag = reg_userPassword.test(userPassword);
        if (flag) {
            $("#userPassword").css("border", "");
        } else {
            layer.tips('密码需满足6到10位', '#userPassword');
            $("#userPassword").css("border", "1px solid red");
        }
        return flag;
    }
    function checkUserRepassword() {
        var userRepassword = $('#userRepassword').val();
        var flag = (userRepassword == userPassword);
        if (flag) {
            $("#userRepassword").css("border", "");
        } else {
            layer.tips('两次密码不一致', '#userRepassword');
            $("#userRepassword").css("border", "1px solid red");
        }
        return flag;
    }
    $('#btn-update').click(function (){
        var userName = $('#userName').val();
        if(checkUserPassword()&&checkUserRepassword()){
            $.post(
                "updatepassword.do",
                {"userName":userName,"userPassword":userPassword},
                function (data){
                    if (data.status == 0) {
                        window.location.href = "toLogin.do";
                    } else if (data.status == 1) {
                        layer.msg(data.message);
                    }
                }
            );
        }else {
            layer.msg("信息不完整");
        }
    })
</script>
</html>
